-
Notifications
You must be signed in to change notification settings - Fork 113
Remove use of JSONEncoder for Error Reporting #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
eb97558
to
82507ad
Compare
var bytes = [UInt8]() | ||
bytes.append(UInt8(ascii: "{")) | ||
bytes.append(contentsOf: #""errorType":"# .utf8) | ||
self.encodeString(self.errorType, bytes: &bytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errorType is a const string with 2 possible values, we I think we may be able to get away with not encoding it. it can become an enum with a string raw value + big comment above to make sure in anyone adds a value in the future they are aware of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can save the encoding time. on the other, if the errorType is just a plain string, the encoding is just one scan (O(n)) and one copy. I doubt that we would see a performance gain in anything bigger than nanoseconds, while adding developer complexity.
your choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay I guess its safer this way if anyone adds an errorType in the future that has special characters although the likelihood of that is close to zero
return bytes | ||
} | ||
|
||
private func encodeString(_ string: String, bytes: inout [UInt8]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should go to Utils, or at least as a floating function in the file as we may find other use for it in the future beyond ErrorResponse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good a couple of small nits
c9f8869
to
23bf155
Compare
23bf155
to
4f7da75
Compare
Motivation
AWSLambdaRuntime
to not link Foundation. For this we need to remove the use ofJSONEncoder
for error reporting.Changes